package logic

import (
	"cloud-disk/core/internal/svc"
	"cloud-disk/core/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
	return &UserDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserDetailLogic) UserDetail(req *types.UserDetailRequest) (resp *types.UserDetailResponse, err error) {
	resp = new(types.UserDetailResponse)
	user, err := l.svcCtx.UserModel.GetUserByIdentity(req.Identity)
	if err != nil {
		resp.Message = err.Error()
		resp.Code = 100
		return resp, nil
	}

	userDetail := types.User{
		Id:    int64(user.Id),
		Name:  user.Name,
		Email: user.Email,
	}
	resp.User = userDetail
	resp.Message = "ok"
	resp.Code = 200
	return resp, nil
}
